[C#] LINQ Group By


In some scenarios, we would like to select each first one row
of the group which we group by personId.

The following code block is a simple example.

var memberList =
    memberSourceData.GroupBy(item => item.personId)
        .Select(chunck => chunck
            .OrderByDescending(c => c.Id)
            .First())
        .ToList();
#C#






你可能感興趣的文章

[Note] HTML常用標籤介紹

[Note] HTML常用標籤介紹

5. 實際開發 ToDo List 案例

5. 實際開發 ToDo List 案例

1789. Primary Department for Each Employee

1789. Primary Department for Each Employee






留言討論